import type { RegisterImportForm, RegisterQuery, RegisterVO } from './model';

import type { ID, IDS, PageQuery, PageResult } from '#/api/common';

import { commonExport, ContentTypeEnum } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 分页查询登记列表
 * @param params
 * @param data
 * @returns 登记列表
 */
export function registerPage(params?: PageQuery, data?: RegisterQuery) {
  return requestClient.post<PageResult<RegisterVO>>('/register/page', data, {
    params,
  });
}

/**
 * 查询登记列表
 * @param params
 * @returns 登记列表
 */
export function registerList(params?: RegisterQuery) {
  return requestClient.get<RegisterVO[]>('/register/list', { params });
}

/**
 * 导出登记列表
 * @param params
 * @returns 登记列表
 */
export function registerExport(params?: RegisterQuery) {
  return commonExport('/register/export', params ?? {});
}

/**
 * 导入登记数据
 * @param data
 * @returns void
 */
export function registerImport(data: RegisterImportForm) {
  return requestClient.postWithMsg<void>('/register/importExcel', data, {
    headers: {
      'Content-Type': ContentTypeEnum.FORM_DATA,
    },
    isTransformResponse: false,
  });
}

/**
 * 下载登记导入模板
 * @returns blob
 */
export function registerDownloadImportTemplate(params?: RegisterQuery) {
  return commonExport('/register/importTemplate', params ?? {});
}

/**
 * 查询登记详情
 * @param id id
 * @returns 登记详情
 */
export function registerInfo(id: ID) {
  return requestClient.get<RegisterVO>(`/register/${id}`);
}

/**
 * 删除登记
 * @param id id
 * @returns void
 */
export function registerRemove(id: ID | IDS) {
  return requestClient.deleteWithMsg<void>(`/register/${id}`);
}

/**
 * 按筛选条件添加登记人员到收藏夹
 * @param data
 */
export function registerAddFavoriteBySearch(data: any) {
  return requestClient.postWithMsg<void>(`/register/addFavoriteBySearch`, data);
}
